package com.rsk.service.impl;


import java.util.Date;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import com.alibaba.dubbo.config.annotation.Service;
import com.rsk.dao.SysLevelRepository;
import com.rsk.entity.SysLevel;
import com.rsk.service.SysLevelService;
import com.rsk.utils.algorithm.SnowflakeIdWorker;


@Service(interfaceClass = SysLevelService.class)
public class SysLevelServiceImpl implements SysLevelService{
	
	@Autowired
	private SysLevelRepository sysLevelRepository;

	@Transactional
	public int saveSysLevel(String levelName, String levelCode, Long deptId, Long operatorUser) {
		List<Map<String, Object>> list = sysLevelRepository.selectSysLevelByLevelCode(levelCode);
		if(list.isEmpty()||list.size()<0){
			SysLevel sysLevel = new SysLevel();
			sysLevel.setId(SnowflakeIdWorker.generateId(true));
			sysLevel.setLevelName(levelName);
			sysLevel.setLevelCode(levelCode);
			sysLevel.setOperatorUser(operatorUser);
			sysLevel.setOperatorTime(new Date());
			sysLevelRepository.saveAndFlush(sysLevel);
			return 1;
		}else{
			return 0;
		}
	}

	@Transactional
	public int updateSysLevel(Long id, String levelName, Long operatorUser) {
		return sysLevelRepository.updateSysLevel(id, levelName, operatorUser);
	}

	@Transactional
	public int delSysLevel(Long id, Long operatorUser) {
		return sysLevelRepository.delSysLevel(id, operatorUser);
	}

}
